package demo;

import dao.ClassDao;
import dao.StudentDao;
import model.Classes;
import model.Student;
import sun.plugin2.message.Message;

import java.text.MessageFormat;
import java.util.List;
import java.util.Scanner;

/**
 * @author tongchen
 * @create 2022-12-29 9:57
 */
public class exer2 {
    public static void main(String[] args) {
        Scanner scan=new Scanner(System.in);
        //1.查询班级id
        ClassDao classDao = new ClassDao();
        System.out.println("请输入班级名称");
        String className=scan.next();

        Classes classIdByName = classDao.getClassIdByName(className);
        if(classIdByName==null){
            System.out.println("不存在该班级");
            return;
        }
        System.out.println("该班级的id为："+classIdByName.getId());
        //2.查询学生id
        System.out.println("请输入学生姓名");
        String name=scan.next();
        StudentDao studentDao = new StudentDao();
        List<Student> list = studentDao.selectOne(name);
        if(list==null){
            System.out.println("不存在该同学");
            return;
        }
        for (Student student:list) {
            String format = MessageFormat.format("编号:{0}\t|学号：{1}\t|name:{2}\t|email:{3}\t|classid:{4}\t", student.getId(), student
                    .getSn(), student.getName(), student.getEmail(), student.getClassId());
            System.out.println(format);
        }
        System.out.println("请输入你要修改的学生id");
        int id=scan.nextInt();
        System.out.println("请输入你要修改的学生班级");
        int classId = scan.nextInt();
        int i = studentDao.updateClass(id, classId);
        if(i>0){
            System.out.println("修改成功");
        }
        else {

        }

    }
}
